package com.webtest.fileupload;

import com.webtest.mvctest2.dao.DaoBase;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/8/22 17:09
 */
public class FileInfoDao extends DaoBase<FileInfo> {
    public List<FileInfo> getFileInfos() {
        String sql = "select id, fileName, filePath, fileDesc FROM fileinfo";
        return getForList(sql);
    }

    public void addFiles(List<FileInfo> files) {
        if (CollectionUtils.isNotEmpty(files)) {
            String sql = "INSERT INTO fileinfo (fileName, filePath, fileDesc) VALUES(?,?,?)";
            files.forEach(file -> {
                update(sql, file.getFileName(), file.getFilePath(), file.getFileDesc());
            });
        }
    }

    public FileInfo getFileInfo(long id) {
        String sql = "select id, fileName, filePath, fileDesc FROM fileinfo WHERE id=?";
        return get(sql, id);
    }
}
